package iterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class ListIteratorDemo {

    public static void main(String[] args) {

        List<String> list = new ArrayList<>();
        list.add("1111");
        list.add("2222");
        list.add("3333");
        list.add("4444");


        Iterator<String> listI = list.iterator();
        while (listI.hasNext()){

        }



        ListIterator<String> iterator = list.listIterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next() + ">> " + iterator.nextIndex() + ">> " + iterator.previousIndex());
        }
        for(String s : list){
            System.out.println( ">> " + iterator.nextIndex() + ">> " + iterator.previousIndex());
        }
        ListIterator<String> iterator1 = list.listIterator(2);
        while(iterator1.hasNext()){
//            System.out.println(iterator1.next() + ">> " + iterator1.nextIndex() + ">> " + iterator1.previousIndex());
            iterator1.next();
            iterator1.set("aaaaa");
        }
        System.out.println(list);
    }
}
